qui(function(require, exports, module) {
    Sginal.Status = function (options) {
        this.dao = Sginal.Dao;
        this.options = $.extend(true, {}, options);

        this.util = Sginal.Util || {};
        this.config = Sginal.config || {};
    };

    Com.inherits(Sginal.Status, Ancestor.Grid).extend({
        run: function (options, callback) {
            var self = this;
            var $container = self.options.$container;
            var gridConfig = self.getGridConfig(Sginal.Config.TABLE_STATUS, Sginal.Config.TABLE_STATUS_COLMODEL_CONFIG);
            var $form = $container.find('form[name="basicFrm"]');
            var params={};

            self.$grid = $container.find('#statusList');
            params=self.getStatusParam();
            options = $.extend(true, {
                width: 1800,
                shrinkToFit: false,
                autowidth: false,
                postData:params,
                loadComplete:function(){
                    self.$grid.find("tr").not(":first").each(function(i,ele){
                        $(ele).children().eq(0).html(params['fatherId']);
                        $(ele).children().eq(1).html(params['name']);
                    });
                }
            }, gridConfig, options);
            self.$grid.jqGrid(options);
            self.perpareData();

            self.bindFormEvent($form);
            self.bindEvent();
        },

        query: function () {
            var self = this;
            var $container = self.options.$container;
            var $grid = self.$grid;

            self.overridePostData($grid);
            var params = self.getFormParam();
            $grid.jqGrid('setGridParam', {
                postData: params,
                loadComplete:function(){
                    $grid.find("tr").not(":first").each(function(i,ele){
                        $(ele).children().eq(0).html(params['fatherId']);
                        $(ele).children().eq(1).html(params['name']);
                    });
                }
            }).trigger('reloadGrid', [{
                page: 1,
            }]);


        },

        perpareData: function () {
            var self = this;
            var username = $("div.user a.name").html();
        },


        bindEvent: function () {
            var self = this;
            var $container = self.options.$container;
            var $submit = $container.find('.query-btn');


            $submit.on('click', function () {
                self.query();
                return false;
            });
        },

        getStatusParam: function () {
            var $container = this.options.$container;
            var self = this;
            var info = location.search.slice(1);
            var param = {};
            if (info.length > 0) {
                var fatherId = info.split("&")[0].split("=")[1];
                var serverIp = info.split("&")[1].split("=")[1];
                var name = decodeURI(info.split("&")[2].split("=")[1]);
                $container.find('#today').click();
                param['fatherId'] = fatherId;
                param['serverIp'] = serverIp;
                param['name']= name;
                param['startDate']=$("input[name='startDate']").val();
                param['endDate']=$("input[name='endDate']").val();
                $("input[name='fatherId']").val(fatherId);
                $("input[name='serverIp']").val(serverIp);
                $("input[name='name']").val(name);

            }
            return param;
        },

        getFormParam: function () {
            var $container = this.options.$container;
            var self = this;
            var $form = $container.find('form[name="basicFrm"]');
            var info = location.search.slice(1);
            var param = {};
            if (info.length > 0) {
                param['name']=info.split("&")[2].split("=")[1];
            }

            $form.find('input').each(function(i,ele){
                if(i==0){
                    var fatherId = $(ele).val().trim();
                    param['fatherId']=fatherId;
                }

                if(i==1){
                    var serverIp = $(ele).val().trim();
                    param['serverIp']=serverIp;
                }

                if(i==2){
                    var startDate = $(ele).val().trim();
                    param['startDate']=startDate;
                }

                if(i==3){
                    var endDate = $(ele).val().trim();
                    param['endDate']=endDate;
                }

                if(i==4){
                    var name = $(ele).val().trim();
                    param['name']=name;
                }
            });


            return param;
        },

        bindFormEvent: function($form) {
            var self = this;
            $form.find('input[name="startDate"]').datetimepicker({
                onClose: function(selectedDate) {
                    $form.find('input[name="endDate"]').datepicker("option", "minDate", selectedDate);
                },

            });

            $form.find('input[name="endDate"]').datetimepicker({
                onClose: function(selectedDate) {
                    $form.find('input[name="startDate"]').datepicker("option", "maxDate", selectedDate);
                },

            });

            fillFieldNameWhenChangeSelect($form, 'query-select-control', 'query-input-text');
        },

    });
});
